#ifndef __ALGOCHANNEL_H
#define __ALGOCHANNEL_H

#include <pthread.h>
#include "YoloV5.h"
#include <opencv2/core.hpp>
#include <vector>
#include <mutex>
typedef void (*ALGOCHANNEL_DETECTPROC)(std::vector<DRESULT> results);

class AlgoChannel
{
public:
    AlgoChannel(/* args */);
    ~AlgoChannel();
    int Init(char *pucModelPath,int iModelWidth,int iModelHeight);
    int Destory();
    int setDetectDataCallback(ALGOCHANNEL_DETECTPROC cb);
private:
    std::mutex  m_mutex;
    std::vector<DRESULT> m_sendResults;

    std::vector<BBOX> CalResult(std::vector<BBOX>& detections,int ModelWidth,int ModelHeight);
    int CropYuvData(void* pMBlk,void **pdstMBlk,unsigned int width,unsigned int height);
    void* ProcData(void* arg);
    int yuv420ToCvMat(void *ptr, int dstW, int dstH, cv::Mat &image);
    int drawInfo(void* pImage, std::vector<DRESULT> results);
private:
    pthread_t m_phOutOSThread;
    pthread_t m_phSendThread;
    bool m_exit = false;
    int m_modelWidth = 0;
    int m_modelHeight = 0;
    YoloV5 m_yolov;
    ALGOCHANNEL_DETECTPROC m_cb;
private:
    void onProcDataCallBack();
    void onSendDataCallBack();


public:
    static void *setProcDataCallBack(void *user);
    static void *setSendDataCallBack(void *user);
};


#endif
